
// 邀请路人组队 {"id":"11"}

// @ts-ignore
export async function execute(client_id,message_json) {
    let target_id = message_json["id"];

    let login_characters = G.Characters.get_current_login_characters(client_id);

    let target_characters = _CharactersData.get(target_id);
    if (target_characters === undefined) {
        ClientUtils.send_basic_prompt(client_id, "用户不存在或已下线！");
        return;
    }
    let target_team_data = G.TeamUtils.get_team_data(target_characters["队伍"]);
    //对方有队伍
    if (target_team_data !== undefined) {
        ClientUtils.send_basic_prompt(client_id, "对方已在队伍中！");
        return;
    }
    let my_level = login_characters["等级"]
    let target_level = target_characters["等级"]
    if (my_level - target_level > 100 || target_level - my_level > 100) {
        ClientUtils.send_basic_prompt(client_id, "等级相差100禁止邀请组队");
    }

    // 没有队伍 先创建一个
    let my_team_data = G.TeamUtils.get_team_data(login_characters["队伍"]);
    if (my_team_data === undefined) {
        G.TeamUtils.create_team(login_characters["id"]);
    }
    login_characters = G.Characters.get_current_login_characters(client_id);
    my_team_data = G.TeamUtils.get_team_data(login_characters["队伍"]);
    let target_client_id = G.Characters.get_characters_client_id(target_id);
    if (target_client_id !== undefined) {
        G.TeamUtils.cache_team_invite(my_team_data["id"], login_characters["id"], target_id);
        ClientUtils.send_client_message(target_client_id, 4018, {
            "队长id": my_team_data["id"],
            "PK开关": login_characters["PK开关"],
            "等级": login_characters["等级"],
            "名称": login_characters["名称"],
            "模型": login_characters["模型"],
            "邀请id": login_characters["id"],
        });
        ClientUtils.send_basic_prompt(client_id, `你已邀请#G${target_characters["名称"]}#加入队伍，请等待对方回应^^`);
        G.TeamUtils.send_team_message(my_team_data["id"], `#G${login_characters["名称"]}#邀请#G${target_characters["名称"]}#加入队伍`);
    }
}
